package tgc.edu.ljc.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Transient;

import org.springframework.data.annotation.CreatedBy;

import com.fasterxml.jackson.annotation.JsonIgnore;

import tgc.edu.ljc.custom.BaseEntity;

/**
 * 文件表
 * 
 * @author zmq
 *
 */
@Entity
public class SysFile extends BaseEntity<Integer> {
	private String fileTitle; // 文件标题
	private String fileName; // 文件名
	private DataSum fileNature; // 文件性质 0：公共 1：私有 2：上级部门+同级部门私有
	private String uploadsUsername; // 上传者用户名
	private String uploadsName; // 上传者姓名
	@JsonIgnore
	private SysDept userDept; // 上传文件人部门
	private DataSum fileType; // 文件类型
	private String fileTypeUrl;// 此文件类型存放的地址
	private String updateTime; // 上传文件时间
	private String fileSize; // 文件大小
	private String fileRemark; // 文件备注
	private String delTime; // 文件删除时间
	private String fileUuid; // 文件UUID
	@JsonIgnore
	private SysFile parent; // 上级目录
	@JsonIgnore
	private List<SysFile> children = new ArrayList<>();// 下级文件/目录

	public String getFileTitle() {
		return fileTitle;
	}

	public void setFileTitle(String fileTitle) {
		this.fileTitle = fileTitle;
	}

	public String getUploadsUsername() {
		return uploadsUsername;
	}

	public void setUploadsUsername(String uploadsUsername) {
		this.uploadsUsername = uploadsUsername;
	}

	public String getUploadsName() {
		return uploadsName;
	}

	public void setUploadsName(String uploadsName) {
		this.uploadsName = uploadsName;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	@ManyToOne
	@CreatedBy
	public DataSum getFileType() {
		return fileType;
	}

	public void setFileType(DataSum fileType) {
		this.fileType = fileType;
	}

	public String getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}

	public String getFileSize() {
		return fileSize;
	}

	public void setFileSize(String fileSize) {
		this.fileSize = fileSize;
	}

	@ManyToOne
	@CreatedBy
	public SysFile getParent() {
		return parent;
	}

	public void setParent(SysFile parent) {
		this.parent = parent;
	}

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "parent")
	@OrderBy(value = "updateTime")
	public List<SysFile> getChildren() {
		return children;
	}

	public void setChildren(List<SysFile> children) {
		this.children = children;
	}

	@ManyToOne
	@CreatedBy
	public DataSum getFileNature() {
		return fileNature;
	}

	public void setFileNature(DataSum fileNature) {
		this.fileNature = fileNature;
	}

	public String getFileRemark() {
		return fileRemark;
	}

	public void setFileRemark(String fileRemark) {
		this.fileRemark = fileRemark;
	}

	public String getDelTime() {
		return delTime;
	}

	public void setDelTime(String delTime) {
		this.delTime = delTime;
	}

	@ManyToOne
	@CreatedBy
	public SysDept getUserDept() {
		return userDept;
	}

	public void setUserDept(SysDept userDept) {
		this.userDept = userDept;
	}

	@Transient
	public String getDeptName() {
		return userDept == null ? "" : userDept.getName();
	}

	public String getFileUuid() {
		return fileUuid;
	}

	public void setFileUuid(String fileUuid) {
		this.fileUuid = fileUuid;
	}

	public String getFileTypeUrl() {
		return fileTypeUrl;
	}

	public void setFileTypeUrl(String fileTypeUrl) {
		this.fileTypeUrl = fileTypeUrl;
	}
	
	@Transient
	public String getFileTypeName() {
		String fileTypeName=fileType==null?"":fileType.getName();
		return fileTypeName;
	}
}
